package cn.it.http.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.context.annotation.SessionScope;

@Controller
//加载到session域中
@RequestMapping("/mvc")
@SessionAttributes(value = {"name","pwd"},types = {String.class,Integer.class})
public class Test2 {
    /*Modelspring的一个接口，该接口有一个实现类ExtendeModelMop
    * 该类继承了ModelMap，而ModelMap是LinkedHashMap的子类，所以使用model和map是一样的效果
    * */
    @RequestMapping("/testtype")
    public String type(Model model){
        model.addAttribute("name","老王");
        model.addAttribute("pwd","123");
        return "index";
    }

    /*如果想获取数据就要用到get方法，所以使用MdelMap*/
    @RequestMapping("/testGet")
    public String testGet(ModelMap modelMap){
        System.out.println(modelMap.get("name") + ";" + modelMap.get("pwd"));

        return "index";
    }

    /*SessionStatus用于移除Session中的数据*/
    @RequestMapping("/complete")
    public String complete(SessionStatus sessionStatus){
        sessionStatus.setComplete();

        return "index";
    }
}
